﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;


namespace Web.Settle
{
    public partial class CheckOutHistory : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
               // DataBind("");
            }
        }
        private void DataBind(string WBName)
        {


            //获取存粮信息
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT top 100 B.strName AS WBName,A.ID,A.SA_AN,A.Variety_Name,Weight_Mao,Weight_Pi,Weight_Jing,Weight_Reality,CONVERT(VARCHAR(100),dt_Trade,23) AS dt_Trade");
            strSql.Append("  FROM dbo.SA_CheckOut A INNER JOIN WB B ON A.WBID=B.ID");
          
            if (WBName.ToString().Trim() != "")
            {
                strSql.Append("   WHERE B.strName = '" + WBName + "'");
            }

            strSql.Append("  ORDER BY A.dt_Trade DESC");


            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
            Repeater1.DataSource = dt;
            Repeater1.DataBind();

        }

        public string GetVarietyName(object objVarietyID)
        {
            int num = 1;
            if (int.TryParse(objVarietyID.ToString(), out num))
            {
                return SQLHelper.ExecuteScalar(" SELECT strName FROM dbo.StorageVariety WHERE ID=" + objVarietyID.ToString()).ToString();

            }
            else {
                return objVarietyID.ToString();
            }
        }



        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" SELECT COUNT(A.ID)");
            strSql.Append(" FROM dbo.SA_Account A INNER JOIN dbo.WB B ON A.WBID=B.ID");
            strSql.Append(" WHERE B.strName ='" + txtWBID.Value.Trim() + "'");
            object objWB = SQLHelper.ExecuteScalar(strSql.ToString());
            if (Convert.ToInt32(objWB) <= 0)
            {
                Fun.Alert("您查询的网点不存在或该网点尚未出库开户");
                return;
            }
            DataBind(txtWBID.Value);
        }
    }
}